<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>设备台账</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <link rel="stylesheet" href="../../layuiadmin/layui/css/layui.css" media="all">
  <link rel="stylesheet" href="../../layuiadmin/style/admin.css" media="all">
</head>
<body>
  <div class="layui-fluid">
    <div class="layui-card">
      <div class="layui-card-body">
            <div class="equipment-wrap search-container">
                <div class="title-row">
                    <i class="layui-icon layui-icon-list" style="font-size: 20px; vertical-align: middle"></i>
                    <span>资材信息查询</span>
                </div>
                <div class="layui-row search-row layui-form">
                    <div class="layui-col-md8 layui-form-item">
                        <label class="layui-form-label" style="text-align:left">关键字：</label>
                        <div class="layui-input-block">
                            <input type="text" name="match"  placeholder="请输入关键字(资材编号、名称、类型)进行查找..." autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-col-md4" style="text-align: center">
                        <button class="layui-btn layuiadmin-btn-admin" lay-submit  lay-filter="LAY-user-back-search">
                            <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                            查询
                        </button>
                    </div>
                </div>
                <div class="station-row">
                    <i class="layui-icon layui-icon-list"></i>
                    <span data-v-a0401034="">站点列表</span>
                    <i class="layui-icon layui-icon-down station-list-btn"></i>
                </div>
                <div class="station-list layui-form">
                    <div class="layui-row list-row" style="position: relative;">
                        <div class="station-list-box"></div>
                        <div class="operateBtn">
                            <button class="layui-btn layuiadmin-btn-admin" lay-submit id="searchBtn">查询</button>
                            <button class="layui-btn layuiadmin-btn-admin" lay-submit  id="emptyBtn">清空</button>
                        </div>
                    </div>
                </div>
            </div>
            <div class="equipment-wrap">
                <div class="title-row">
                    <i class="layui-icon layui-icon-list" style="font-size: 20px; vertical-align: middle"></i>
                    <span>资材信息</span>
                </div>
                <div class="table-wrap">
                    <div id="exportButton" style="padding-bottom: 10px;"></div>
                    <script type="text/html" id="exportButtonTpl">
                        {{# if(d){ }}
                            <button id="down-load-button" class="layui-btn layuiadmin-btn-admin" data-type="add"><i class="layui-icon layui-icon-download-circle"></i> 导出</button>
                        {{# } }}
                    </script>
                    <table id="LAY-equipment-account" lay-filter="LAY-equipment-account"></table>
                </div>
                <script type="text/html" id="table-content-list">
                    {{# if((layui.data(layui.setter.tableName).user_info.menuAndPermissionList.indexOf('equipment_ledger_page:detailed_info')) > -1){ }}
                        <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="detail">查看详情</a>
                    {{# } }}
                </script>
            </div>
          </div>
    </div>
  </div>
<script src='../../layuiadmin/modules/jTools.js'></script>
<script src="../../layuiadmin/layui/layui.js"></script>
<script>
    layui.config({
        base: '../../layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
        , my_send: '../myModules/my_send'
        , excel: '../layui_ext/excel'
    }).use(['index', 'equipment', 'table', 'laytpl','excel'], function(){
        var $ = layui.$
        ,form = layui.form
        , setter = layui.setter
        , table = layui.table
        , laytpl = layui.laytpl
        , http_proxy = layui.http_proxy
        , excel = layui.excel;

        //按钮权限控制
        var getTpl = exportButtonTpl.innerHTML;
        var view = document.getElementById("exportButton");
        laytpl(getTpl).render($.inArray('equipment_ledger_page:export',layui.data(setter.tableName).user_info.menuAndPermissionList),function(html){
            view.innerHTML = html;
        })
        //点击查询按钮，重载表格
        form.on('submit(LAY-user-back-search)', function (data) {
            //执行重载
            table.reload('LAY-equipment-account', {
                where: data.field
            });
        });
        var stationIds= [];
        form.on('checkbox(cOne)', function (data) {
            if(data.elem.checked === true){
                stationIds.push(data.elem.title);
            }else {
                stationIds.splice(stationIds.indexOf(this.title), 1);
            }
        });
        $("#searchBtn").click(function(){
            table.reload('LAY-equipment-account', {
                where:{
                    stationIds:stationIds,
                    systemName: jTools.getQuery('systemName','无'),
                    etType: jTools.getQuery('etType','无'),
                    match: jTools.getQuery('match','')
                }
                ,done:function(res){
                    this.where={};
                }
            });
        });
        $("#emptyBtn").click(function(){
            $(".stationId").prop("checked", false);
            stationIds= [];
            form.render('checkbox');
            table.reload('LAY-equipment-account', {
                where:{
                    stationIds:stationIds,
                    systemName: jTools.getQuery('systemName','无'),
                    etType: jTools.getQuery('etType','无'),
                    match: jTools.getQuery('match','')
                }
            });
        });

        //事件
        var active = {
        batchdel: function(){
            var checkStatus = table.checkStatus('LAY-equipment-plan')
            ,checkData = checkStatus.data; //得到选中的数据

            if(checkData.length === 0){
            return layer.msg('请选择数据');
            }

            layer.confirm('确定删除吗？', function(index) {

            //执行 Ajax 后重载
            /*
            admin.req({
                url: 'xxx'
                //,……
            });
            */
            table.reload('LAY-equipment-plan');
            layer.msg('已删除');
            });
        },
        add: function(){
            layer.open({
            type: 2
            ,title: '添加新角色'
            ,content: 'roleform.html'
            ,area: ['500px', '480px']
            ,btn: ['确定', '取消']
            ,yes: function(index, layero){
                var iframeWindow = window['layui-layer-iframe'+ index]
                ,submit = layero.find('iframe').contents().find("#LAY-user-role-submit");

                //监听提交
                iframeWindow.layui.form.on('submit(LAY-user-role-submit)', function(data){
                var field = data.field; //获取提交的字段

                //提交 Ajax 成功后，静态更新表格中的数据
                //$.ajax({});
                table.reload('LAY-user-back-role');
                layer.close(index); //关闭弹层
                });

                submit.trigger('click');
            }
            });
        }
        }
        $('.layui-btn.layuiadmin-btn-role').on('click', function(){
        var type = $(this).data('type');
        active[type] ? active[type].call(this) : '';
        });

        $("#down-load-button").on('click', function(){
            var stationIds = []
            $.each($(".grid-content-cell.bg-purple > input"),function(i,n){
                stationIds.push(n.title)
            })
            var param = {
                systemName : jTools.getQuery('systemName','无'),
                etType : jTools.getQuery('etType','无'),
                match : $('[name=match]').val(),
                stationIds : stationIds
            }
            $.ajax({
                url: http_proxy('/equipmentLAIM/downloadCateTemplate')
                , type: 'post'
                , contentType:"application/json"
                , data: JSON.stringify(param)
                , responseType: 'blob'
                , success: function (req) {
                    if(req.rows.length > 0){
                        req.rows.unshift({
                            etCode:'资材编号',
                            etName:'资材名称',
                            etType:'资材类型',
                            etComment:'资材描述',
                            domain:'资材大类编号',
                            systemName:'资材小类编号',
                            createdId:'创建人编号',
                            createdName:'创建人姓名',
                            createdTime:'创建时间',
                            owner:'所属单位',
                            etModel:'规格型号',
                            etSupplier:'供应商',
                            etProducer:'制作商',
                            dateOfProduction:'出厂日期',
                            guaranteePeriod:'保修期至',
                            serialNum:'产品序列号',
                            professionalId:'专业类别编号',
                            voltage:'额定电压',
                            power:'额定功率',
                            life:'使用寿命',
                            lineId:'线路编号',
                            stationName:'所属站点',
                            installLocation:'安装位置',
                            installDate:'安装日期',
                            plannedStr:'是否维护计划',
                            maintainFirstTime:'首次维修计划日期',
                            maintainThisTime:'本次维护计划日期',
                            maintainNextTime:'预计下次维护计划日期',
                            maintain_next_day:'距离下次维护计划时间（天）',
                            intervalDay:'维修间隔天数'
                        })
                        var data = excel.filterExportData(req.rows,[
                            'etCode',
                            'etName',
                            'etType',
                            'etComment',
                            'domain',
                            'systemName',
                            'createdId',
                            'createdName',
                            'createdTime',
                            'owner',
                            'etModel',
                            'etSupplier',
                            'etProducer',
                            'dateOfProduction',
                            'guaranteePeriod',
                            'serialNum',
                            'professionalId',
                            'voltage',
                            'power',
                            'life',
                            'lineId',
                            'stationName',
                            'installLocation',
                            'installDate',
                            'plannedStr',
                            'maintainFirstTime',
                            'maintainThisTime',
                            'maintainNextTime',
                            'maintain_next_day',
                            'intervalDay'
                        ])
                        excel.exportExcel({
                            sheet1: data
                        }, '资材列表'+getFormatDate()+'.xlsx','xlsx')
                    }
                }
            })
        })

        function getFormatDate() {
            var date = new Date();
            var month = date.getMonth() + 1;
            var strDate = date.getDate();
            if (month >= 1 && month <= 9) {
                month = "0" + month;
            }
            if (strDate >= 0 && strDate <= 9) {
                strDate = "0" + strDate;
            }
            var currentDate = date.getFullYear() + "-" + month + "-" + strDate;
            return currentDate;
        }
    });
</script>
</body>
</html>
